/*
 *  ActFancerMachine.h
 *  hreem
 *
 *  Created by James Holodnak on 4/17/09.
 *  Copyright 2009 James Holodnak. All rights reserved.
 *
 */


#ifndef __ActFancerMachine_h__
#define __ActFancerMachine_h__

#include "Machine.h"
#include "cpu/deadhu6280/deadhu6280.h"
#include "cpu/dead6502/dead6502.h"
#include "apu/ym2203/ym2203.h"
//#include "apu/ym3812/ym3812.h"
//#include "apu/oki6295/oki6295.h"

class CActFancerMachine:public CMachine
{
public:
	CDeadHu6280 *MainCPU;			//main cpu pointer
	CDead6502 *SoundCPU;			//sound cpu pointer

protected:
	u8 MainROM[0x20000];
	u8 SoundROM[0x4000];
	u8 CharROM[0x2000];
	u8 TileROM[0xC000];
	u8 SpriteROM[0x10000];
	u8 PROM[0x1000];

	u8 RAM[0x1000];
	u8 VRAM[0x1000];
	u8 SoundRAM[0x800];
	u8 SpriteRAM[0x80];

	u8 *BankPtr;
	u8 BankNum;
	u8 SoundLatch;

	u8 VBlank;					//vblank status
	int Scanline;				//current scanline

	u8 DoSoundIRQ;

	u32 Palette[256];			//converted palette

	u8 CharLookup[256];			//palette lookup tables
	u8 SpriteLookup[256];
	u8 BackgroundLookup[256 * 4];
	
	u8 Screen[256 * (256+16)];	//screen drawn to

	int HighScoresLoaded;

protected:
	void DecodePalette();
	void DrawChar(unsigned char *dest,int pitch,unsigned char tile);
	void DrawTile(unsigned char *dest,int pitch,unsigned char tile);

public:
	CActFancerMachine();
	virtual ~CActFancerMachine();
	virtual int Init();
	virtual void Kill();
	virtual void Reset();
	virtual void Blit();
	virtual void Line(u32 mainc,u32 soundc,int irq);
	virtual void Frame();
	virtual void SaveState(CState *s);
	virtual void LoadState(CState *s);
	virtual void SaveScores();
	virtual void LoadScores();
	virtual void RenderScreen(u8 *dest,int pitch);
	void RenderChars(u8 *dest,int pitch);
	void RenderTiles(u8 *dest,int pitch);
	static u8 ReadMainCPU(void *user,u32 addr);
	static void WriteMainCPU(void *user,u32 addr,u8 data);
	static u8 ReadSoundCPU(void *user,u32 addr);
	static void WriteSoundCPU(void *user,u32 addr,u8 data);
	static u8 MainIRQ(void *user);
	static u8 SoundIRQ(void *user);
	static void ProcessSound(void *user,void *data,int len);
	virtual int FPS(){return(60);}
};

#endif

